﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Contronller;
using Contronller.Interface;

namespace Web_NhaMay.UC
{
    public partial class uc_Menu : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadMenu();
        }

        ICategory ca = new Category();
        private void LoadMenu()
        {
            DataTable dt = ca.LoadMenu();
            DataList1.DataSource = dt;
            DataList1.DataBind();
        }

        protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            Label id = (Label)e.Item.FindControl("lbID"); //Find main category id
            int catid = Convert.ToInt16(id.Text.ToString());
            DataTable dt = ca.LoadMenuSub(catid);
            DataList d = (DataList)e.Item.FindControl("subcat"); //Find another gridview
            d.DataSource = dt;
            d.DataBind();
        }
    }
}